<?php

function showEventInfo($inEvent){
    settype($inEvent,"integer");
    $sql = sprintf("SELECT * FROM events WHERE ID = %s", $inEvent);
    $res = sendQ($sql);
    
    $info = "";
	$title = "";
	$max = 0;
    
    while(($row = mysql_fetch_array($res))!=null){
            $title = $row['name'];
            $info = $row['info'];
            $max = $row['max'];
    }
	
	$info = utf8_encode($info);
	$title = utf8_encode($title);

	$out = '<div id="showevent"><div id="rightTab" class="head1"></div><h1>' . $title . '</h1><div id="eventInfo">' . $info . '</div></div><hr>';
	
	return $out;
}

function showEventList($inEvent,$type = ""){
	settype($inEvent,"integer");
	
	$eventID = $inEvent . $type;
    $sql = "SELECT event_" . $eventID . ".SN, event_" . $eventID . ".name, ";
            if($type == ""){
    		$sql .= "event_" . $eventID . ".paidStatus,";
            }
	$sql .= "members.SN AS isMem
			FROM event_" . $eventID . "
			LEFT JOIN members ON event_" . $eventID . ".SN = members.SN";
    $res = sendQ($sql);
    
    $pars = array();
    $k = 0;
    $out = "";
    
    while(($row = mysql_fetch_array($res))!=null){
            $cur = array();
            $cur['SN'] = $row['SN'];
            $cur['name'] = $row['name'];
            
            if($row['isMem'] == null){
            	$cur['isMem'] = false;
            }else{
            	$cur['isMem'] = $row['isMem'];
            }
            if($type == ""){
                    $cur['paidStatus'] = $row['paidStatus'];
            }
            array_push($pars,$cur);
            $k++;
    }
        
	if($k > 0){
	$out .=	'<div id="eventTable"><table>
				<tr style="padding-top: 10px; padding-bottom: 10px;">
						<th style="width: 250px;padding-top: 10px; padding-bottom: 10px; text-align: left;">' . $k . ' tilmeldte </th>	
						<th style="padding-top: 10px; padding-bottom: 10px;border-right: 1px dotted #aaa;">Medlem: </th>
						<th style="padding-top: 10px; padding-bottom: 10px;">Betalings status:</th>
				</tr>';
			
		for($i = 0; $i < $k;$i++){
			$name = utf8_encode($pars[$i]['name']);
			if($pars[$i]['name'] != ""){
				 
				$out .= '<tr id="eventlist"  >
						<td class="eventlistsn">' .$name . '</td>';
						
				if($pars[$i]['isMem']){
					$out .= '<td class="paidstatus" id="haspayed0" >';
					$out .= '<img id="statusimg" src="style/yes.png" ></td>';
				}else{
					$out .= '<td class="paidstatus" id="notpayed0" >';
					$out .= '<img id="statusimg" src="style/no.png" ></td>';
				}		
				
				if($pars[$i]['paidStatus']){
					$out .= '<td class="paidstatus" id="haspayed0" >';
					$out .= '<img id="statusimg" src="style/yes.png" ></td>';
				}else{
					$out .= '<td class="paidstatus" id="notpayed0" >';
					$out .= '<img id="statusimg" src="style/no.png" ></td>';
				}

				$out .= '</tr>';
			}
		}
				$out .= '</table></div>';
			
	}else{
			$out .= '<p>No one has registred</p>';
	}
	return $out;
}

function showEventWaitlist($inEvent){
	$event = getEvent($inEvent,"_waitlist");
	$wl = $event['0'];
	
	$out = 	'<div id="showevent"><div id="rightTab" class="head1"></div><h1>Ventelisten - ' . $event['title'] . '</h1></div>'.
			'<div id="eventTable"><table>
			<tr style="padding-top: 10px; padding-bottom: 10px;">
					<th style="width: 250px;padding-top: 10px; padding-bottom: 10px; text-align: left;">' . $event['cur'] . ' tilmeldte </th>	
					<th style="padding-top: 10px; padding-bottom: 10px;border-right: 1px dotted #aaa;">Medlem: </th>
					<th style="padding-top: 10px; padding-bottom: 10px;">Betalings status:</th>
			</tr>';

	foreach($wl as $wlpar) {
		
			if($wlpar['name'] != ""){
				$out .= '<tr id="eventlist"><td class="eventlistsn">' . utf8_encode($wlpar['name']) . '</td>';
				if($wlpar['isMem'] == true){
					$out .= '<td class="paidstatus" id="haspayed0" >';
					$out .= '<img id="statusimg" src="style/yes.png" ></td>';
				}else{
					$out .= '<td class="paidstatus" id="notpayed0" >';
					$out .= '<img id="statusimg" src="style/no.png" ></td>';
				}

				$out .= '</tr>';
			}
	}
	$out .= '</table></div>';
	
	return $out;
}
?>